<% if @promotion.multi_codes? %>
  <% coupon_codes_count = @promotion.coupon_codes.count %>
  <% if coupon_codes_count.positive? %>
    <% used_coupon_codes_count = @promotion.coupon_codes.used.count %>

    <div class="card mb-4">
      <div class="card-header d-flex justify-content-between">
        <h5 class="card-title">
          <%= Spree.t(:coupon_codes) %>
        </h5>
        <%= link_to_with_icon 'eye', Spree.t(:view), spree.admin_promotion_coupon_codes_path(@promotion), class: 'btn btn-sm btn-light' %>
      </div>
      <div class="card-body">
        <%= progress_bar_component(used_coupon_codes_count, max: coupon_codes_count) %>
      </div>
      <div class="card-footer d-flex justify-content-between">
        <span class="badge badge-light">
          <%= Spree.t(:used) %>: <%= used_coupon_codes_count %> / <%= coupon_codes_count %>
        </span>
        <span class="badge badge-light">
          Remaining: <%= coupon_codes_count - used_coupon_codes_count %>
        </span>
      </div>
    </div>
  <% end %>
<% end %>

<%= turbo_frame_tag :promotion_edit_details do %>
  <div class="card mb-4">
    <div class="card-header d-flex justify-content-between">
      <h5 class="card-title">
        <%= Spree.t(:details) %>
      </h5>
      <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_promotion_path(@promotion), icon: 'pencil', class: 'btn btn-sm btn-light' %>
    </div>
    <div class="card-body p-0">
      <ul class="list-group list-group-flush">
        <li class="list-group-item d-flex justify-content-between align-items-center">
          <span class="text-muted">
            <%= Spree.t(:name) %>
          </span>
          <span>
            <%= @promotion.name %>
          </span>
        </li>

        <li class="list-group-item d-flex justify-content-between align-items-center">
          <span class="text-muted">
            <%= Spree.t(:created_at) %>
          </span>
          <span>
            <%= spree_time(@promotion.created_at, format: :long) %>
          </span>
        </li>

        <li class="list-group-item d-flex justify-content-between align-items-center">
          <span class="text-muted">
            <%= Spree.t(:updated_at) %>
          </span>
          <span>
            <%= spree_time(@promotion.updated_at, format: :long) %>
          </span>
        </li>

        <li class="list-group-item d-flex justify-content-between align-items-center">
          <span class="text-muted">
            <%= Spree.t(:kind) %>
          </span>
          <span class="badge badge-light">
            <%= @promotion.kind.titleize %>
          </span>
        </li>

        <% if @promotion.code.present? %>
          <li class="list-group-item d-flex justify-content-between align-items-center py-2">
            <span class="text-muted"><%= Spree.t(:coupon_code) %></span>
            <div class="d-flex align-items-center gap-1">
              <code><%= @promotion.code.upcase %></code>
              <%= clipboard_component(@promotion.code.upcase) %>
            </div>
          </li>
        <% end %>
      </ul>
    </div>
  </div>
<% end%>

<%= turbo_frame_tag :promotion_edit_settings do %>
  <div class="card">
    <div class="card-header d-flex justify-content-between">
      <h5 class="card-title">
        <%= Spree.t(:settings) %>
      </h5>
      <%= link_to_with_icon 'edit', Spree.t(:edit), spree.edit_admin_promotion_path(@promotion), icon: 'pencil', class: 'btn btn-sm btn-light' %>
    </div>
    <div class="card-body p-0">
      <ul class="list-group list-group-flush">
        <% unless @promotion.multi_codes? %>
          <li class="list-group-item d-flex justify-content-between align-items-center">
            <span class="text-muted"><%= Spree.t(:usage_limit) %></span>
            <%= render 'spree/admin/promotions/usage_limit', promotion: @promotion %>
          </li>
        <% end %>
        <li class="list-group-item d-flex justify-content-between align-items-center">
          <span class="text-muted">
            <%= I18n.t('activerecord.attributes.spree/promotion.starts_at') %>
          </span>
          <% if @promotion.starts_at %>
            <span><%= spree_time(@promotion.starts_at) %></span>
          <% else %>
            <span class="text-muted"><%= Spree.t(:not_available) %></span>
          <% end %>
        </li>
        <li class="list-group-item d-flex justify-content-between align-items-center">
          <span class="text-muted">
            <%= Spree.t(:expires_at) %>
          </span>
          <% if @promotion.expires_at %>
            <span><%= spree_time(@promotion.expires_at) %></span>
          <% else %>
            <span class="text-muted"><%= Spree.t(:not_available) %></span>
          <% end %>
        </li>
      </ul>
    </div>
  </div>
<% end %>